'use strict';

var _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault');
var _interopRequireWildcard = require('@babel/runtime/helpers/interopRequireWildcard');
Object.defineProperty(exports, '__esModule', {
  value: true,
});
exports.default = void 0;
var _objectSpread2 = _interopRequireDefault(require('@babel/runtime/helpers/objectSpread2'));
var _objectWithoutProperties2 = _interopRequireDefault(
  require('@babel/runtime/helpers/objectWithoutProperties'),
);
var _react = _interopRequireWildcard(require('react'));
var _antd = require('antd');
var _createField = _interopRequireDefault(require('../../../createField'));
var _useOptions2 = _interopRequireDefault(require('../../../hooks/useOptions'));
var _useOther2 = _interopRequireDefault(require('../../../hooks/useOther'));
var _FieldContext = require('../../../contexts/FieldContext');
require('./index.css');
var _excluded = ['value', 'onChange', 'options', 'itemProps'];
var CheckboxWithOther = function CheckboxWithOther(_ref) {
  var value = _ref.value,
    onChange = _ref.onChange,
    optionsProp = _ref.options,
    itemProps = _ref.itemProps,
    rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var _useOptions = (0, _useOptions2.default)(optionsProp),
    options = _useOptions.options;
  var _useFieldContext = (0, _FieldContext.useFieldContext)(),
    label = _useFieldContext.label;
  var _useOther = (0, _useOther2.default)({
      value: value,
      onChange: onChange,
      options: options,
    }),
    otherChecked = _useOther.otherChecked,
    changeOtherChecked = _useOther.changeOtherChecked,
    selectedValue = _useOther.selectedValue,
    changeSelectedValue = _useOther.changeSelectedValue,
    otherValue = _useOther.otherValue,
    changeOtherValue = _useOther.changeOtherValue;
  return /*#__PURE__*/ _react.default.createElement(
    _react.Fragment,
    null,
    /*#__PURE__*/ _react.default.createElement(
      _antd.Checkbox.Group,
      (0, _objectSpread2.default)(
        (0, _objectSpread2.default)(
          {
            value: selectedValue,
            onChange: changeSelectedValue,
          },
          rest,
        ),
        {},
        {
          style: {
            marginRight: 10,
          },
        },
      ),
      options.map(function (item) {
        return /*#__PURE__*/ _react.default.createElement(
          _antd.Checkbox,
          (0, _objectSpread2.default)(
            {
              key: item.value,
              value: item.value,
            },
            typeof itemProps == 'function' ? itemProps(item) : itemProps,
          ),
          item.label,
        );
      }),
    ),
    /*#__PURE__*/ _react.default.createElement(
      _antd.Checkbox,
      {
        checked: otherChecked,
        onChange: function onChange(event) {
          return changeOtherChecked(
            event === null || event === void 0 ? void 0 : event.target.checked,
          );
        },
      },
      '\u5176\u4ED6',
    ),
    otherChecked
      ? /*#__PURE__*/ _react.default.createElement(_antd.Input, {
          placeholder: '\u8BF7\u8F93\u5165'.concat(label || ''),
          style: {
            width: 120,
          },
          maxLength: 100,
          value: otherValue,
          onChange: function onChange(event) {
            return changeOtherValue(
              event === null || event === void 0 ? void 0 : event.target.value,
            );
          },
        })
      : null,
  );
};
var _default = (0, _createField.default)(CheckboxWithOther);
exports.default = _default;
